#!/bin/bash

TLE=predict.tle

echo "struct {
char* name;
int year;
float refepoch;
float drag;
float incl;
float raan;
float eccn; 
float argper;
float meanan;
float meanmo;
long orbitnum;
} satdata[] = {"

#SATFILTER="AO-85\|AO-91\|AO-92\|Fox-1Cliff\|ISS\|AO-95\|SO-50"
SATFILTER="ISS"

( cat $TLE |tr -d '\r' | while read a
do
    name=`echo $a|sed -e 's/^/"/' -e 's/ //g' -e 's/$/"/g'`
    echo -n "{" $name ","

    read b
    declare -a ST=(1 1 3 8 10 12 15 19 21 34 45 54 63 65 69)
    declare -a EN=(1 1 7 8 11 14 17 20 32 43 52 61 63 68 69)
    for i in 7 8 9
    do
	start=${ST[i]}
	end=${EN[i]}
	el=`echo "$b"|cut -b ${start}-${end}`
	echo -n $el ", "
    done
    
    read c
    # replace char 26 with "." so extracted value looks like a float
    d=${c::25}"."${c:26} 
    declare -a ST=(1 1 3  9 18 26 35 44 53 64 69)
    declare -a EN=(1 1 7 16 25 33 42 51 63 68 69)
    for i in 3 4 5 6 7 8 9
    do
	start=${ST[i]}
	end=${EN[i]}
	el=`echo "$d"|cut -b ${start}-${end}`
	echo -n $el ", "
    done
    echo
done
) | sed -e 's/ ,/,/g' -e 's/, /,/g' -e 's/,$/ },/' -e 's/,/, /g' \
  | sed -e 's/ 0/ /g' -e 's/ 0/ /g' -e 's/ 0/ /g' -e 's/ 0/ /g' \
  | grep -e $SATFILTER
echo "};"

exit

FMN 1
1 43192U 18015A   18053.61707976  .00002823  00000-0  12517-3 0  9998
2 43192 097.3376 185.0385 0016792 180.5779 179.5441 15.22288024003084

    # sat.year = atoi (SubString (line1, 18, 19));
    # sat.refepoch = atof (SubString (line1, 20, 31));
    # sat.drag = atof (SubString (line1, 33, 42));
    #
    #7:sat.year
    #8.refepoch
    #9.drag

    # sat.incl = atof (SubString (line2, 8, 15));
    # sat.raan = atof (SubString (line2, 17, 24));
    # sat.eccn = atof (SubString (line2, 25, 32));
    # sat.argper = atof (SubString (line2, 34, 41));
    # sat.meanan = atof (SubString (line2, 43, 50));
    # sat.meanmo = atof (SubString (line2, 52, 62));
    # sat.orbitnum = atof (SubString (line2, 63, 67));

    # 3.incl
    # 4.raan
    # 5.eccn -- note needs "0."
    # 6.argper
    # 7.meanan
    # 8.meanmo
    # 9.orbitnum
